package com.yu.juctest;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo {
    //案例： 让主线程等待5个子线程完成工作才能进行汇总
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch downLatch = new CountDownLatch(5);
        for (int i = 1; i <=5 ; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"已完成工作");
                downLatch.countDown();

            },String.valueOf(i)+"号子线程").start();
        }
        downLatch.await();
        System.out.println("主线程等待完成，开始进行汇总");
    }

}
